from celery.decorators import task
from nc_mlpa.mlpa.models import MlpaMpa, MpaArray
from django.shortcuts import get_object_or_404

'''
add and named_add are used for testing purposes
they may come in handy down the road for continued
and simplified testing of celeryd and ghettoq
'''
@task
def add(x, y):
    #import time
    #time.sleep(10)
    return x + y

@task
def named_add(x=0, y=0):
    return x + y
    
'''
Will be called from the lingcod.async app 
To prevent possible race conditions task parameters should be passed 
the id's of django objects rather than the django objects themselves.
'''
@task
def compile_mpa_results_async(mpa_id, group):    
    from MpaAnalysis import get_mpa_results
    mpa = get_object_or_404(MlpaMpa, pk=mpa_id)
    return get_mpa_results(mpa, group)
   
@task
def compile_array_results_async(array_id, group):
    from ArrayAnalysis import compile_array_results
    array = get_object_or_404(MpaArray, pk=array_id)
    return compile_array_results(array, group)
